/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BLL;
import DBH.DBHelper;
import com.sun.org.glassfish.external.statistics.Statistic;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
/**
 *
 * @author Huy
 */
public class Loaisanpham {
    
    private DBHelper obj = new DBHelper();
    private Vector v;
    private String idloaisp;
    private String ten ;

    public Loaisanpham(){}
    public Loaisanpham(String idloaisp,String ten){
        this.idloaisp=idloaisp;
        this.ten=ten;
    }
            public int Insertloaisanpham(Loaisanpham b) throws SQLException
    {
        int i=0;
        try
        {
            Vector paramList=new Vector();
            paramList.add(b.getIdloaisp());
            paramList.add(b.getTen());         
            i=DBHelper.executeUpdate("sp_Insertloaisanpham",paramList);
        }
        catch(SQLException sqlex)
        {
            
        }
        return i;
    }
   public int Updateloaisanpham(Loaisanpham b) throws SQLException
    {
        int i=0;
        try
        {
            Vector paramList=new Vector();
            paramList.add(b.getIdloaisp());
            paramList.add(b.getTen());         
            i=DBHelper.executeUpdate("sp_Updateloaisanpham",paramList); 
        }
        catch(SQLException sqlex)
        {
            
        }
        return i;
    }
 public int Deleteloaisanpham(String idloaisp) throws SQLException
    {
        int i=0;
        try
        {
            Vector paramList=new Vector();
            paramList.add(idloaisp);            
            i=DBHelper.executeUpdate("sp_Deleteloaisanpham",paramList);
        }
        catch(SQLException sqlex)
        {
            
        }
        return i;
    }  
   public  Vector getAllloaisanpham() throws SQLException
    {
        Vector v = new Vector();
        try 
        {
            ResultSet rs = obj.executeQuery("sp_getAllloaisanpham");
            while(rs.next())
            {    
                Loaisanpham b = new Loaisanpham();
                b.setIdloaisp(rs.getString(1));
                b.setTen(rs.getString(2));
                v.add(b);  
            }
        } 
        catch(SQLException sqle) 
        {            
        }
        return v;        
    }
  public  Vector getloaispName(String name) throws SQLException
    {
        Vector v = new Vector();
        Vector paramList=new Vector();
        paramList.add(name);               
        try 
        {
            ResultSet rs = DBHelper.executeQuery("sploaisp_name",paramList);
            while(rs.next())
            {                 
               Loaisanpham b = new Loaisanpham();
                b.setIdloaisp(rs.getString(1));
                b.setTen(rs.getString(2));
             
                v.add(b);                        
            }
        } 
        catch(SQLException sqle) 
        {            
        }
        return v;        
    }
    public String getIdloaisp() {
        return idloaisp;
    }

    /**
     * @param idloaisp the idloaisp to set
     */
    public void setIdloaisp(String idloaisp) {
        this.idloaisp = idloaisp;
    }

    /**
     * @return the ten
     */
    public String getTen() {
        return ten;
    }

    /**
     * @param ten the ten to set
     */
    public void setTen(String ten) {
        this.ten = ten;
    }
    
}
